package ch15;

import java.util.HashSet;
import java.util.LinkedList;

import java.util.Set;
import java.util.regex.Pattern;

public class SetCompany {
    private String companyName;
    private String address;
    private String phone;
    private String range;
    Set set=new HashSet();

    public SetCompany() {
    }

    public SetCompany(String companyName, String address, String phone, String range) {
        this.companyName = companyName;
        this.address = address;
        this.phone = phone;
        this.range = range;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRange() {
        return range;
    }

    public void setRange(String range) {
        this.range = range;
    }

    //添加员工
    public boolean setSet(SetStaff staff) {
        for(Object o:set){
            SetStaff setStaff=(SetStaff)o;
            if(setStaff.getNo().equals(staff.getNo())){
                return false;
            }
        }
        /*for(int i=0;i<set.size();i++) {
            SetStaff staff1=(SetStaff)set.get(i);
            if (staff.getNo().equals(staff1.getNo())){
                return false;
            }
        }*/
        set.add(staff);
        return true;
    }

    //显示员工信息
    public void showStaff(){
        for(Object o:set){
            SetStaff s=(SetStaff)o;
            System.out.println("姓名："+s.getName()+",年龄："+s.getAge()+",性别："+s.getGender()+
                    "职位:"+s.getPost()+",薪资："+s.getSalary()+",工号："+s.getNo());
        }
    }

    //显示公司信息(String companyName, String address, String phone, String range)
    public void showCompany(){
        System.out.println("公司信息如下：");
        System.out.println("公司名称:"+companyName+",注册地址："+address+
                ",公司电话："+",公司经营范围："+range+",公司现有"+set.size()+"人");
    }

    //显示工资最高的员工信息
    public void maxSalary(){//有问题：
        if(set.size()==0){
            System.out.println("还没有员工");
        }else {
            double realMax = 0;

            //将员工薪资放进数组中
            for(Object o:set){
                SetStaff setStaff=(SetStaff)o;
                if(realMax<setStaff.getSalary()){
                    realMax=setStaff.getSalary();
                }
            }
            System.out.println("员工最高薪资:"+realMax);
            /*if(set.contains(realMax)){
                System.out.println(set);
            }*/
        }
    }

    //开除员工
    public boolean delete(String no){

        for(Object o:set){
            SetStaff setStaff=(SetStaff)o;
            if(no.equals(setStaff.getNo())){
               set.remove(setStaff);
               return true;
            }
        }
       /*  int in=0;
       for(int i=0;i<set.size();i++) {
            SetStaff deleteStaff = (SetStaff) set.get(i);
            if (no.equals(deleteStaff.getNo())){
                in=i;
                set.remove(in);
                return true;
            }
        }*/
        return false;
    }

}
